#include <iostream>
#include <string>
using std::cout;
using std::string;
using std::endl;
//实现FILE指针的正确回收资源

class SafeFile{
public:
    SafeFile(const char * filename)
    :_fp(fopen(filename, "a+"))
    {

    }


    void write(const string & message){
        fwrite( message.c_str(), 1, message.size(), _fp);
    }


    ~SafeFile(){
        fclose(_fp);
    }


private:
    FILE * _fp;
};


void test(){
    SafeFile sf("hello.txt");
    sf.write("hello world, hello c++");
    sf.write("hello python, hello jjjjj");
}

int main()
{
    test();
    return 0;
}

